package algorithms.paixu;

import edu.princeton.cs.algs4.*;
import org.omg.CORBA.ARG_IN;
import org.springframework.util.StopWatch;

import java.util.Random;


/**
 * @功能
 * @创建时间 2020/11/23
 */
public class SortCompare {
    public static double time(String alg ,Double[] a){
        StopWatch timer = new StopWatch();
        long i = System.currentTimeMillis();
        if(alg.equals("Insertion"))
            Insertion.sort(a);
        if(alg.equals("Selection"))
            Selection.sort(a);
        if(alg.equals("Shell"))
            Shell.sort(a);
        if(alg.equals("Merge"))
            Merge.sort(a);
        if(alg.equals("Quick"))
            Quick.sort(a);
        if(alg.equals("Heap"))
            Heap.sort(a);

 return System.currentTimeMillis()-i;
    }
    public static double timeRandomInput(String alg,int N,int T){
        double total =0.0;
        Double[] a = new Double[N];
        for(int t=0;t<T;t++) {
            for (int i = 0; i < N; i++)
                a[i] = StdRandom.uniform();
            total += time(alg, a);


        }
            return total;


    }

    public static void main(String[] args) {
        String alg1="Selection";
        String alg2="Insertion";
        int N = 1000;//Integer.parseInt(args[2]);
        int T = 100;//Integer.parseInt(args[3]);
        double t1 = timeRandomInput(alg1,N,T);
        double t2 = timeRandomInput(alg2,N,T);
        System.out.println(T+"次测试"+alg1+"faster than"+ alg2+ t2/t1+"倍");

    }
}
